<template>
	<view>
		<scroll-view scroll-y="true" class="content" :enhanced="true" :bounces="false" :show-scrollbar="false">
			<view class="login">
				<view class="my_center2 h50p">
					<view>
						<u--image :showLoading="true" :src="BASE_URL+'/upload/logo.png'" width="192rpx" height="192rpx"></u--image>
					</view>
					<view class="fs20 mt15">车优多</view>
				</view>
				<view class="w100p h50p">
					<view>
						<view class="header"></view>
						<button class="bottom mb15" type="primary" open-type="getPhoneNumber" :disabled="!radioShow"
							@getphonenumber="onGetPhoneNumber">授权手机号</button>
					</view>

					<view class="d-flex j-center a-center">
						<label class="" @click="radioClick()">
							<radio style="transform:scale(0.6)" color="#007AFF" :checked="radioShow" />
						</label>
						<view class="fs12" style="color: #999999;">我已阅读并同意</view>
						<view class="fs12" style="color: #ca875c;" @click="openUserPolicyPage()">《用户服务协议》</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		login,
		queryFileListByApp
	} from "@/api/index.js"
	import {
		BASE_URL
	} from "@/utils/common.js"

	export default {
		data() {
			return {
				BASE_URL: BASE_URL,
				radioShow: false,
				fileUrl: ""
			};
		},
		onLoad() {},
		onShow() {
			this.queryFileListByApp()
		},
		methods: {
			queryFileListByApp() {
				const that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				queryFileListByApp().then(res => {
					const list = res.object
					let obj = {}
					for (var i = 0; i < list.length; i++) {
						switch (list[i].fileName) {
							case 'diamonds':
								obj.diamonds = list[i].fileUrl
								break;
							case 'privileges':
								obj.privileges = list[i].fileUrl
								break;
							case 'orderFlow':
								obj.orderFlow = list[i].fileUrl
								break;
							case 'rechargeFlow':
								obj.rechargeFlow = list[i].fileUrl
								break;
							case 'privacyPolicy':
								obj.privacyPolicy = list[i].fileUrl
								break;
							case 'userPolicy':
								obj.userPolicy = list[i].fileUrl
								that.fileUrl = list[i].fileUrl
								break;
						}
					}
					uni.hideLoading()
					uni.setStorageSync('iconInfo', obj)
				})
			},

			openUserPolicyPage() {
				uni.navigateTo({
					url: "/subpkg_my/userManual/userManual?type=2&fileUrl=" + this.fileUrl
				});
			},

			radioClick() {
				this.radioShow = !this.radioShow
			},
			onGetPhoneNumber(e) {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				login({
					wxPhoneCode: e.detail.code
				}).then(res => {
					if (res.status == '200') {
						uni.hideLoading()
						uni.setStorageSync('userInfo', res.object)
						uni.reLaunch({ //信息更新成功后跳转到小程序首页
							url: '/pages/role/index'
						});

					}

				})
			},

		}
	}
</script>

<style>
	.content {
		//可视高度，需要在多大的盒子中进行滑动
		height: 100vh;
		width: 100%;
	}

	.login {
		font-family: Source Han Sans CN, Source Han Sans CN-500;
		height: 100vh;
	}

	.header {}

	.bottom {
		border-radius: 16rpx;
		margin: 0rpx 94rpx;
		font-size: 35rpx;
	}
</style>